2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
25 * Include file for SDL mouse event handling.
31 #include "SDL_stdinc.h"
32 #include "SDL_error.h"
33 #include "SDL_video.h"
35 #include "begin_code.h"
36 /* Set up for C function definitions, even when using C++ */
41 typedef struct SDL_Cursor SDL_Cursor
; /* Implementation dependent */
44 * \brief Cursor types for SDL_CreateSystemCursor.
48 SDL_SYSTEM_CURSOR_ARROW
, /**< Arrow */
49 SDL_SYSTEM_CURSOR_IBEAM
, /**< I-beam */
50 SDL_SYSTEM_CURSOR_WAIT
, /**< Wait */
51 SDL_SYSTEM_CURSOR_CROSSHAIR
, /**< Crosshair */
52 SDL_SYSTEM_CURSOR_WAITARROW
, /**< Small wait cursor (or Wait if not available) */
53 SDL_SYSTEM_CURSOR_SIZENWSE
, /**< Double arrow pointing northwest and southeast */
54 SDL_SYSTEM_CURSOR_SIZENESW
, /**< Double arrow pointing northeast and southwest */
55 SDL_SYSTEM_CURSOR_SIZEWE
, /**< Double arrow pointing west and east */
56 SDL_SYSTEM_CURSOR_SIZENS
, /**< Double arrow pointing north and south */
57 SDL_SYSTEM_CURSOR_SIZEALL
, /**< Four pointed arrow pointing north, south, east, and west */
58 SDL_SYSTEM_CURSOR_NO
, /**< Slashed circle or crossbones */
59 SDL_SYSTEM_CURSOR_HAND
, /**< Hand */
60 SDL_NUM_SYSTEM_CURSORS
64 * \brief Scroll direction types for the Scroll event
68 SDL_MOUSEWHEEL_NORMAL
, /**< The scroll direction is normal */
69 SDL_MOUSEWHEEL_FLIPPED
/**< The scroll direction is flipped / natural */
70 } SDL_MouseWheelDirection
;
72 /* Function prototypes */
75 * \brief Get the window which currently has mouse focus.
77 extern DECLSPEC SDL_Window
* SDLCALL
SDL_GetMouseFocus(void);
80 * \brief Retrieve the current state of the mouse.
82 * The current button state is returned as a button bitmask, which can
83 * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
84 * mouse cursor position relative to the focus window for the currently
85 * selected mouse. You can pass NULL for either x or y.
87 extern DECLSPEC Uint32 SDLCALL
SDL_GetMouseState(int *x
, int *y
);
90 * \brief Get the current state of the mouse, in relation to the desktop
92 * This works just like SDL_GetMouseState(), but the coordinates will be
93 * reported relative to the top-left of the desktop. This can be useful if
94 * you need to track the mouse outside of a specific window and
95 * SDL_CaptureMouse() doesn't fit your needs. For example, it could be
96 * useful if you need to track the mouse while dragging a window, where
97 * coordinates relative to a window might not be in sync at all times.
99 * \note SDL_GetMouseState() returns the mouse position as SDL understands
100 * it from the last pump of the event queue. This function, however,
101 * queries the OS for the current mouse position, and as such, might
102 * be a slightly less efficient function. Unless you know what you're
103 * doing and have a good reason to use this function, you probably want
104 * SDL_GetMouseState() instead.
106 * \param x Returns the current X coord, relative to the desktop. Can be NULL.
107 * \param y Returns the current Y coord, relative to the desktop. Can be NULL.
108 * \return The current button state as a bitmask, which can be tested using the SDL_BUTTON(X) macros.
110 * \sa SDL_GetMouseState
112 extern DECLSPEC Uint32 SDLCALL
SDL_GetGlobalMouseState(int *x
, int *y
);
115 * \brief Retrieve the relative state of the mouse.
117 * The current button state is returned as a button bitmask, which can
118 * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
119 * mouse deltas since the last call to SDL_GetRelativeMouseState().
121 extern DECLSPEC Uint32 SDLCALL
SDL_GetRelativeMouseState(int *x
, int *y
);
124 * \brief Moves the mouse to the given position within the window.
126 * \param window The window to move the mouse into, or NULL for the current mouse focus
127 * \param x The x coordinate within the window
128 * \param y The y coordinate within the window
130 * \note This function generates a mouse motion event
132 extern DECLSPEC
void SDLCALL
SDL_WarpMouseInWindow(SDL_Window
* window
,
136 * \brief Moves the mouse to the given position in global screen space.
138 * \param x The x coordinate
139 * \param y The y coordinate
140 * \return 0 on success, -1 on error (usually: unsupported by a platform).
142 * \note This function generates a mouse motion event
144 extern DECLSPEC
int SDLCALL
SDL_WarpMouseGlobal(int x
, int y
);
147 * \brief Set relative mouse mode.
149 * \param enabled Whether or not to enable relative mode
151 * \return 0 on success, or -1 if relative mode is not supported.
153 * While the mouse is in relative mode, the cursor is hidden, and the
154 * driver will try to report continuous motion in the current window.
155 * Only relative motion events will be delivered, the mouse position
158 * \note This function will flush any pending mouse motion.
160 * \sa SDL_GetRelativeMouseMode()
162 extern DECLSPEC
int SDLCALL
SDL_SetRelativeMouseMode(SDL_bool enabled
);
165 * \brief Capture the mouse, to track input outside an SDL window.
167 * \param enabled Whether or not to enable capturing
169 * Capturing enables your app to obtain mouse events globally, instead of
170 * just within your window. Not all video targets support this function.
171 * When capturing is enabled, the current window will get all mouse events,
172 * but unlike relative mode, no change is made to the cursor and it is
173 * not restrained to your window.
175 * This function may also deny mouse input to other windows--both those in
176 * your application and others on the system--so you should use this
177 * function sparingly, and in small bursts. For example, you might want to
178 * track the mouse while the user is dragging something, until the user
179 * releases a mouse button. It is not recommended that you capture the mouse
180 * for long periods of time, such as the entire time your app is running.
182 * While captured, mouse events still report coordinates relative to the
183 * current (foreground) window, but those coordinates may be outside the
184 * bounds of the window (including negative values). Capturing is only
185 * allowed for the foreground window. If the window loses focus while
186 * capturing, the capture will be disabled automatically.
188 * While capturing is enabled, the current window will have the
189 * SDL_WINDOW_MOUSE_CAPTURE flag set.
191 * \return 0 on success, or -1 if not supported.
193 extern DECLSPEC
int SDLCALL
SDL_CaptureMouse(SDL_bool enabled
);
196 * \brief Query whether relative mouse mode is enabled.
198 * \sa SDL_SetRelativeMouseMode()
200 extern DECLSPEC SDL_bool SDLCALL
SDL_GetRelativeMouseMode(void);
203 * \brief Create a cursor, using the specified bitmap data and
204 * mask (in MSB format).
206 * The cursor width must be a multiple of 8 bits.
208 * The cursor is created in black and white according to the following:
210 * <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
211 * <tr><td> 0 </td><td> 1 </td><td> White </td></tr>
212 * <tr><td> 1 </td><td> 1 </td><td> Black </td></tr>
213 * <tr><td> 0 </td><td> 0 </td><td> Transparent </td></tr>
214 * <tr><td> 1 </td><td> 0 </td><td> Inverted color if possible, black
218 * \sa SDL_FreeCursor()
220 extern DECLSPEC SDL_Cursor
*SDLCALL
SDL_CreateCursor(const Uint8
* data
,
222 int w
, int h
, int hot_x
,
226 * \brief Create a color cursor.
228 * \sa SDL_FreeCursor()
230 extern DECLSPEC SDL_Cursor
*SDLCALL
SDL_CreateColorCursor(SDL_Surface
*surface
,
235 * \brief Create a system cursor.
237 * \sa SDL_FreeCursor()
239 extern DECLSPEC SDL_Cursor
*SDLCALL
SDL_CreateSystemCursor(SDL_SystemCursor id
);
242 * \brief Set the active cursor.
244 extern DECLSPEC
void SDLCALL
SDL_SetCursor(SDL_Cursor
* cursor
);
247 * \brief Return the active cursor.
249 extern DECLSPEC SDL_Cursor
*SDLCALL
SDL_GetCursor(void);
252 * \brief Return the default cursor.
254 extern DECLSPEC SDL_Cursor
*SDLCALL
SDL_GetDefaultCursor(void);
257 * \brief Frees a cursor created with SDL_CreateCursor().
259 * \sa SDL_CreateCursor()
261 extern DECLSPEC
void SDLCALL
SDL_FreeCursor(SDL_Cursor
* cursor
);
264 * \brief Toggle whether or not the cursor is shown.
266 * \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current
269 * \return 1 if the cursor is shown, or 0 if the cursor is hidden.
271 extern DECLSPEC
int SDLCALL
SDL_ShowCursor(int toggle
);
274 * Used as a mask when testing buttons in buttonstate.
275 * - Button 1: Left mouse button
276 * - Button 2: Middle mouse button
277 * - Button 3: Right mouse button
279 #define SDL_BUTTON(X) (1 << ((X)-1))
280 #define SDL_BUTTON_LEFT 1
281 #define SDL_BUTTON_MIDDLE 2
282 #define SDL_BUTTON_RIGHT 3
283 #define SDL_BUTTON_X1 4
284 #define SDL_BUTTON_X2 5
285 #define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
286 #define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
287 #define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
288 #define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
289 #define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
292 /* Ends C function definitions when using C++ */
296 #include "close_code.h"
298 #endif /* _SDL_mouse_h */
300 /* vi: set ts=4 sw=4 expandtab: */